'''
@文件    :views.py
@说明    :
@时间    :2020/04/05 15:34:58
@作者    :didiplus
@版本    :1.0
'''

from flask import Blueprint,request,json,jsonify,make_response
from .__init__ import *

msg = Blueprint('msg',__name__,url_prefix='/api/msg')

@msg.route('/private',methods=['POST','GET'])
def private():
    # 私信
    query = request_query(request, ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    query["total"] = True
    data = Send(query).POST("weapi/msg/private/users")
    
    return make_response(jsonify(json.loads(data.text)),403)

@msg.route('/history',methods=['POST','GET'])
def history():
    # 私信历史
    query = request_query(request,
                          ["uid", "userId"],
                          ["limit", {"limit": 30}],
                          ["time", {"time": 0}])
    query["total"] = "true"
    data = Send(query).POST("weapi/msg/private/history")
    return make_response(jsonify(json.loads(data.text)),403)

@msg.route('/Sendmsg',methods=['POST','GET'])
def Sendmsg():
    # 发送私信
    query = request_query(request, ["id", {"id": ""}], "msg", "uid")
    query["type"] = "text" if query["id"] == "" else "playlist"
    query["userIds"] = '[{}]'.format(query.pop("uid"))
    data = Send(query).POST("weapi/msg/private/Send")
    return make_response(jsonify(json.loads(data.text)),403)

@msg.route('/comment',methods=['POST','GET'])
def comment():
    # 评论通知
    query = request_query(request, "uid",
                          ["limit", {"limit": 30}],
                          ["time", {"beforeTime": -1}])
    query["total"] = "true"
    data = Send(query).POST("weapi/v1/user/comments/" + query["uid"])
    return make_response(jsonify(json.loads(data.text)),403)

@msg.route('/forwards',methods=['POST','GET'])
def forwards():
    # @我通知
    query = request_query(request, ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    query["total"] = "true"
    data = Send(query).POST('weapi/forwards/get')
    return make_response(jsonify(json.loads(data.text)),403)

@msg.route('/notices',methods=['POST','GET'])
def notices():
    # 通知
    query = request_query(request, ["limit", {"limit": 30}],
                          ["offset", {"offset": 0}])
    query["total"] = "true"
    data = Send(query).POST('weapi/msg/notices')
    return make_response(jsonify(json.loads(data.text)),403)